import {createRouter,createWebHashHistory} from 'vue-router'

import Login from '../components/Login.vue'
import Regist from '../components/Regist.vue'
import ShowSchedule from '../components/ShowSchedule.vue'
import LoginUsernameError from '../components/LoginUsernameError.vue'
import LoginUserPwdError from '../components/LoginUserPwdError.vue'
import RegistFail from '../components/RegistFail.vue'
import RegistSuccess from '../components/RegistSuccess.vue'
import ForgotPassword from '../components/ForgotPassword.vue'
import FaceRecognitionManager from '../components/FaceRecognitionManager.vue'
import SlamManager from '../components/SlamManager.vue'
import AdminVerificationCode from '../views/AdminVerificationCode.vue'
import pinia from "../pinia.js"
import {defineUser} from "../store/userStore.js"

let sysUser=defineUser(pinia)

const router=createRouter({
    history:createWebHashHistory(),
    routes:[
        {
            path:"/",
            redirect:"/showSchedule"
        },
        {
            path:"/showSchedule",
            component:ShowSchedule
        },
        {
            path:"/login",
            component:Login
        },
        {
            path:"/regist",
            component:Regist
        },
        {
            path:"/loginUsernameError",
            component:LoginUsernameError
        },
        {
            path:"/loginUserPwdError",
            component:LoginUserPwdError
        },
        {
            path:"/registFail",
            component:RegistFail
        },
        {
            path:"/registSuccess",
            component:RegistSuccess
        },
        {
            path:"/forgot-password",
            component:ForgotPassword
        },
        {
            path:"/face-recognition",
            component:ShowSchedule,
            props: { defaultTab: 'face-management' }
        },
        {
            path:"/slam-manager",
            component:SlamManager
        },
        {
            path:"/admin/verification-codes",
            component:AdminVerificationCode
        }
    ]
})

//路由的全局守卫  判断是否可以访问需要登录的页面
// 已注释掉路由守卫，用户可以直接访问所有页面
/*
router.beforeEach((to,from,next)=>{
    // 定义需要登录才能访问的页面
    const protectedRoutes = ['/showSchedule', '/slam-manager', '/face-recognition']
    
    // 如果访问的是受保护的页面
    if(protectedRoutes.includes(to.path)){
        // 检查用户是否已登录
        if(sysUser.username==''){
            // 未登录，跳转到登录页面
            next('/login')
        }else{
            // 已登录，放行
            next()
        }
    }else{
        // 访问的是公开页面（登录、注册等），直接放行
        next()
    }
})
*/

export default router